package edu.cmsc611.simulator;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;

public class ReadInput {

	private Vector<Instruction> instructions=new Vector<Instruction>();
	private Instruction tempinstr;
	public ReadInput(){};
	
	public Vector<Instruction> getInstructions() {
		return instructions;
	}

	public void setInstructions(Vector<Instruction> instructions) {
		this.instructions = instructions;
	}

	public void readInstructionFromFile(String instructionFile)
	{
		try {
			File file = new File(instructionFile);
			FileReader fileReader = new FileReader(file);
			BufferedReader bufferedReader = new BufferedReader(fileReader);
			StringBuffer stringBuffer = new StringBuffer();
			String line;
			while ((line = bufferedReader.readLine()) != null) 
			{
				System.out.print(line);
				tempinstr = new Instruction(line);
				System.out.println(tempinstr);
				if (tempinstr.valid() == true)
				{
					instructions.add(tempinstr);
				}
				else
				{
					System.out.println(line+" is invalid instruction");
					return;
				}
				//stringBuffer.append(line);
				//stringBuffer.append("\n");
			}
			fileReader.close();
			System.out.println("Contents of file:");
			System.out.println(stringBuffer.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		try {
			File file = new File("input.txt");
			FileReader fileReader = new FileReader(file);
			BufferedReader bufferedReader = new BufferedReader(fileReader);
			StringBuffer stringBuffer = new StringBuffer();
			String line;
			while ((line = bufferedReader.readLine()) != null) {
				stringBuffer.append(line);
				stringBuffer.append("\n");
			}
			fileReader.close();
			System.out.println("Contents of file:");
			System.out.println(stringBuffer.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}

